package cn.dubito.miaosha.rabbitmq.send;

import cn.dubito.miaosha.rabbitmq.MqConfig;
import cn.dubito.miaosha.rabbitmq.message.SeckillMessage;
import cn.dubito.miaosha.redis.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liliang
 * @description:
 * @date 2018/4/10.
 */
@Service
public class MqSender {

    private static Logger logger = LoggerFactory.getLogger(MqSender.class);

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    private RedisService redisService;

    public void sendSeckillMessage(SeckillMessage message) {
        String msg = redisService.beanToString(message);
        logger.info("send seckill message : {}", msg);
        amqpTemplate.convertAndSend(MqConfig.SECKILL_QUEUE, msg);
    }

//    public void send(Object message) {
//        String msg = redisService.beanToString(message);
//        logger.info("send message : {}", msg);
//        amqpTemplate.convertAndSend(MqConfig.QUEUE, msg);
//    }
//
//    public void sendTopic(Object message) {
//        String msg = redisService.beanToString(message);
//        logger.info("send topic message : {}", msg);
//        amqpTemplate.convertAndSend(MqConfig.TOPIC_EXCHANGE, "topic.key1", msg + "1");
//        amqpTemplate.convertAndSend(MqConfig.TOPIC_EXCHANGE, "topic.#", msg + "2");
//    }
//
//    public void sendFanout(Object message) {
//        String msg = redisService.beanToString(message);
//        logger.info("send fanout message : {}", msg);
//        amqpTemplate.convertAndSend(MqConfig.FANOUT_EXCHANGE, "", msg);
//    }
//
//    public void sendHead(Object message) {
//        String msg = redisService.beanToString(message);
//        logger.info("send header message : {}", msg);
//        MessageProperties properties = new MessageProperties();
//        properties.setHeader("head1","value1");
//        properties.setHeader("head2","value2");
//        Message obj = new Message(msg.getBytes(), properties);
//        amqpTemplate.convertAndSend(MqConfig.HEAD_EXCHANGE, "", obj);
//    }

}
